package com.cyandpos.pad.offline.model;

import android.content.ContentValues;

import com.cyandpos.pad.http.OkHttpUtils;
import com.cyandpos.pad.offline.offlinedb.CursorUtil;
import com.cyandpos.pad.offline.offlinedb.Sqldb;
import com.cyandpos.pad.posdata.Member;

import java.util.Map;

public class OfflineQueryMember {

    public static  void queryMember(Sqldb sqldb, Map<String, Object> params, OkHttpUtils.ResultCallback callback){
       boolean isAdd= (boolean) params.get("isNew");
        Member member=new Member();
       if(isAdd){
           ContentValues values=new ContentValues();
           values.put("ORDERNO",params.get("orderNo")+"");
           values.put("HYKNO",params.get("cardNo")+"");
           values.put("HYKTYPE",params.get("condType")+"");
           boolean isInsert=sqldb.insert("ORDER_MEM",values);
           if(isInsert){
               member.setMemberCardNo(params.get("cardNo")+"");
               member.setMemberCardTypeId(Integer.parseInt(params.get("condType")+""));
               callback.onSuccess(CursorUtil.getOfflineBean(member));
           }else{
               callback.onFailure("添加会员失败!");
           }
       }else{
          boolean isUpdate= sqldb.delete("ORDER_MEM","ORDERNO=?",new String[]{params.get("orderNo")+""});
          if(isUpdate){
              member.setMemberCardNo(params.get("cardNo")+"");
              member.setMemberCardTypeId(Integer.parseInt(params.get("condType")+""));
              callback.onSuccess(CursorUtil.getOfflineBean(member));
          }else{
              callback.onFailure("会员删除失败!");
          }
       }
    }
}
